package com.guinea.account.service;
// Generated 2011-3-28 13:30:19 by Hibernate Tools 3.4.0.Beta1

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

import com.guinea.account.dao.AttachDao;
import com.guinea.account.entity.Attach;
import com.guinea.core.orm.hibernate.HibernateDao;
import com.guinea.core.service.CRUDManager;
import com.guinea.core.utils.CommonUtils;

public class AttachManager extends CRUDManager {

	private AttachDao attachDao;

	public HibernateDao getEntityDao() {
		return getAttachDao();
	}

	public Attach getAttach(Serializable id) {
		return (Attach)getAttachDao().get(id);
	}

	public AttachDao getAttachDao() {
		return attachDao;
	}

	public void setAttachDao(AttachDao attachDao) {
		this.attachDao = attachDao;
	}

	public long getTotalSize(){
		long result = 0;
		List l = getAttachDao().find("from Attach a where a.creator = ? and a.status = '1'", new Object[]{CommonUtils.getCurrentUserId()});
		if(l != null && l.size() > 0){
			for (Iterator iter = l.iterator(); iter.hasNext();) {
				Attach attach = (Attach) iter.next();
				result += attach.getFileSize().longValue();
			}
		}
		return result;
	}
}
